<template>
    <div id="app">
        <router-view></router-view>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                _beforeUnload_time: '',
                _gap_time: ''
            }
        },
        mounted() {
            window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
            window.addEventListener('unload', e => this.unloadHandler(e))
        },
        destroyed() {
            window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
            window.removeEventListener('unload', e => this.unloadHandler(e))
        },
        methods: {
            beforeunloadHandler() {
                this._beforeUnload_time = new Date().getTime();
            },
            unloadHandler(e) {
                this._gap_time = new Date().getTime() - this._beforeUnload_time;
            debugger
                //判断是窗口关闭还是刷新
                if (this._gap_time <= 5) {
                    localStorage.removeItem('userInfo');
                }
            }
        }
    }
</script>
<style>
    @import "./assets/css/main.css";
    @import "./assets/css/color-dark.css"; /*深色主题*/
</style>